package com.example.kotlin;


import com.aserbao.aserbaosandroid.functions.database.greenDao.db.DaoMaster;
import com.aserbao.aserbaosandroid.functions.database.greenDao.db.DaoSession;

/**
 * @author SAN
 */

public class MyDBUtil {

    public static final int ASC = 0;//升序
    public static final int DESC = 1;//降序
    public static final int DEFAULT = 2;//不排序
    private final String DB_NAME = "greendao_mos_main";

    private DaoSession daoSession;
    private DaoMaster daoMaster;
    private MyOpenHelper devOpenHelper;

    private MyDBUtil() {
        super();
    }

    public static MyDBUtil getInstance() {
        return SingletonHolder.INSTANCE;
    }

    private static class SingletonHolder {
        private static MyDBUtil INSTANCE = new MyDBUtil();
    }

    public void init() {
        if (daoSession == null) {
            devOpenHelper = new MyOpenHelper(MyApplication.getContext(), DB_NAME);
            daoMaster = new DaoMaster(devOpenHelper.getWritableDb());
            daoSession = daoMaster.newSession();
        }
    }

    public DaoSession getDaoSession() {
        return daoSession;
    }

    public void setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
    }

//    public void insertOrReplace(Object entry) {
//        if (entry instanceof VehicleConfig) {
//            daoSession.getVehicleConfigDao().insertOrReplace((VehicleConfig) entry);
//        } else if (entry instanceof Vehicle) {
//            daoSession.getVehicleDao().insertOrReplace((Vehicle) entry);
//        } else if (entry instanceof Message) {
//            daoSession.getMessageDao().insertOrReplace((Message) entry);
//        } else if (entry instanceof TravelPoiHistory) {
//            daoSession.getTravelPoiHistoryDao().insertOrReplace((TravelPoiHistory) entry);
//        } else if (entry instanceof OperationNode) {
//            daoSession.getOperationNodeDao().insertOrReplace((OperationNode) entry);
//        } else if (entry instanceof UserSettingsOfChargingStationList) {
//            daoSession.getUserSettingsOfChargingStationListDao().insertOrReplace((UserSettingsOfChargingStationList) entry);
//        } else if (entry instanceof AnimAssetsInfo) {
//            daoSession.insertOrReplace(entry);
//        }
//    }
}
